<template>
  <!-- 应用根容器 -->
  <div class="app-container">
    <!-- 导航栏，仅在登录状态显示 -->
    <nav v-if="isLoggedIn" class="nav-bar">
      <div class="nav-left">
        <router-link to="/chat">聊天</router-link>
      </div>
      <div class="nav-right">
        <router-link to="/profile">个人中心</router-link>
      </div>
    </nav>
    <!-- 路由视图容器 -->
    <router-view></router-view>
  </div>
</template>

<script setup>
import { computed } from 'vue';

// 计算属性：判断用户是否已登录
const isLoggedIn = computed(() => {
  return !!localStorage.getItem('token');
});
</script>

<style>
/* 应用根容器样式 */
.app-container {
  min-height: 100vh;
  /* 背景渐变和图片叠加 */
  background: 
    linear-gradient(rgba(240, 242, 245, 0.75), rgba(240, 242, 245, 0.15)),
    url('https://images.unsplash.com/photo-1451187580459-43490279c0fa?q=80&w=2072&auto=format&fit=crop') center/cover fixed;
  /* 页面加载动画 */
  animation: fadeIn 1.5s ease-out;
}

/* 淡入动画关键帧 */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 导航栏样式 */
.nav-bar {
  padding: 15px 30px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
  animation: slideDown 0.8s ease-out;
}

/* 导航栏滑入动画关键帧 */
@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-100%);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 导航链接样式 */
.nav-bar a {
  color: #333;
  text-decoration: none;
  font-size: 15px;
  padding: 8px 16px;
  border-radius: 6px;
  transition: all 0.3s ease;
}

/* 导航链接悬停效果 */
.nav-bar a:hover {
  transform: translateY(-2px);
}

.nav-bar a.router-link-active {
  color: #007AFF;
  background: rgba(0,122,255,0.1);
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 20px;
}
</style>